import java.lang.reflect.Field;
import java.util.ArrayList;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Main {
	public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, InstantiationException {
		User method2 = method2(User.class);
		System.out.println(method2.getAge());
		
	}
	public static void method(){
		User user=new User();
		user.setName("ddd");
		user.setAge(11);
		user.setId(1);
		Son son=new Son();
		son.setAge(1);
		son.setName("d2");
		son.setFather("ddd");
		user.setSon(son);
		
		User user1=new User();
		user1.setName("ddd");
		user1.setAge(11);
		user1.setId(1);
		Son son1=new Son();
		son1.setAge(1);
		son1.setName("d2");
		son1.setFather("ddd");
		user1.setSon(son1);
		
		ArrayList<User> array=new ArrayList<User>();
		array.add(user);
		array.add(user1);
		
		JSONArray fromObject = JSONArray.fromObject(array);
		System.out.println(fromObject.toString());
	}
	
	public static void method1(){
		String str="{'age':11,'id':1,'name':'ddd','son':{'age':1,'father':'ddd','name':'d2'}}";
		User bean = (User) JSONObject.toBean(JSONObject.fromObject(str), User.class);
		System.out.println("name:"+bean.getName());
		System.out.println("age:"+bean.getAge());
		System.out.println("son name:"+bean.getSon().getName());
	}
	
	public static <T> T method2(Class<T> clazz) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, InstantiationException{
		T newInstance = clazz.newInstance();
		Field name = clazz.getDeclaredField("age");
		name.setAccessible(true);
		name.set(newInstance, 11);
//		String value = (String) name.get(obj);
		return newInstance;
	}
}
